package com.example.liunanxin.lnx226ordering.model;


import com.example.liunanxin.lnx226ordering.beans.ModifyBean;
import com.example.liunanxin.lnx226ordering.iface.ModifyListener;
import com.example.liunanxin.lnx226ordering.iface.Modifyiface;
import com.example.liunanxin.lnx226ordering.retrofitservice.UserinfoService;
import com.example.liunanxin.lnx226ordering.url.Url;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ModifyModel implements Modifyiface {
    private Retrofit retrofit;

    public ModifyModel(){
        retrofit=new Retrofit
                .Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(Url.USERURL)
                .build();
    }

    @Override
    public void updateUserById(int user_id, String username, String userpass, String mobilenum, String address, final ModifyListener modifyListener) {
        UserinfoService userinfoService=retrofit.create(UserinfoService.class);
        Call<ModifyBean> call=userinfoService.updateUserById(user_id, username, userpass, mobilenum, address);
        call.enqueue(new Callback<ModifyBean>() {
            @Override
            public void onResponse(Call<ModifyBean> call, Response<ModifyBean> response) {
                if (response.isSuccessful()&&response!=null){
                    modifyListener.onResponse(response.body());
                }
                else modifyListener.onFail("fail");
            }

            @Override
            public void onFailure(Call<ModifyBean> call, Throwable t) {
                modifyListener.onFail(t.toString());
            }
        });
    }
}
